//
//  DFUIManager.swift
//  DailyFresh
//
//  Created by Arthur on 2017/9/19.
//  Copyright © 2017年 DailyFresh. All rights reserved.
//

import UIKit

class DFUIManager: NSObject {
    
    static let sharedInstance = DFUIManager()
    
    
    fileprivate override init() {
        super.init()
        
        self._setTabBarItems()
        self._setAppearance()
    }
    
    fileprivate func _setTabBarItems() {

        let nav1 = DFNavigationController.init(rootViewController: DFHomeVC())
        let nav2 = DFNavigationController.init(rootViewController: DFWelfareVC())
        let nav3 = DFNavigationController.init(rootViewController: DFShoppingCartVC())
        let nav4 = DFNavigationController.init(rootViewController: DFMineVC())

        tabBarController.viewControllers = [nav1, nav2, nav3, nav4]
    
        let titles = ["首页", "福利社", "购物车", "我的"]
        let normalImages:Array<String> = ["tab_home_23x23_","tab_welfare_23x23_","tab_shopcar_23x23_","tab_mine_23x23_"]
        let highlightImages: Array<String> = ["tab_home_red_23x23_","tab_welfare_red_23x23_","tab_shopcar_red_23x23_","tab_mine_red_23x23_"]
        
        for (index, item) in tabBarController.tabBar.items!.enumerated() {
            item.title = titles[index]
            item.image = UIImage.init(named: normalImages[index])?.withRenderingMode(.alwaysOriginal)
            item.selectedImage = UIImage.init(named: highlightImages[index])?.withRenderingMode(.alwaysOriginal)
        }

    }
    
    fileprivate func _setAppearance() {
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: DFColorConstants.main], for: .selected)
        
        UINavigationBar.appearance().tintColor = .white
        UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red]
    }
    
    // MARK: - Public Methods
    
    public func appRootViewController () -> UIViewController {
        return self.tabBarController
    }
    
    // tab
    lazy var tabBarController: DFTabBarController = {
        [unowned self] in
        let temp = DFTabBarController()
        return temp
    }()
    
//    lazy var 
}
